-------------------
---Titanic Grasp---
--- By Erathorn ---
-------------------

--DEFINES--

DEBUG = true
if(DEBUG == true) then
	logcol(2)
	print("Debug: Earth Titan Encounter Script Loaded...")
	end
TITAN = {} --Define the Titan Table

TITAN.EARTH = 80000 --Earth Titan ID
--TITAN.FIRE = 80001 --Fire Titan ID
--TITAN.FROST = 80002 --Frost Titan ID

-----------------------
--REFERENCE ID's--
-----------------------

--Earth Titan--
--TITAN_EARTH_SPELLS_SHOCK = 61668
--TITAN_EARTH_SPELLS_SHIELD = 68594
--TITAN_EARTH_SPELLS_CLAP = 71147
--TITAN_EARTH_SPELLS_SMASH = 26167

--Fire Titan--
--TITAN.FIRE.SPELLS.SHOCK = 0
--TITAN.FIRE.SPELLS.SHIELD = 0
--TITAN.FIRE.SPELLS.HELLFIRE = 0
--TITAN.FIRE.SPELLS.FISTS = 0

--Frost Titan--
--TITAN.FROST.SPELLS.SHOCK = 0
--TITAN.FROST.SPELLS.SHIELD = 0
--TITAN.FROST.SPELLS.NOVA = 0
--TITAN.FROST.SPELLS.FREEZE = 0
--TITAN.FROST.SPELLS.STRIKE = 0

--END DEFINES--
function TITAN.EARTH_PHASE2(pUnit, pPlayer, event)
	if(pUnit:GetHealthPct() <= 64) then
			if(DEBUG == true) then
		logcol(2)
		print("Debug: Earth Titan - Phase 2 Initiated...")
		end
		pUnit:RemoveEvents()
		pUnit:RegisterEvent("TITAN.EARTH_PHASE3", 1000, 0)
		pUnit:FullCastSpell(68594)
		pUnit:RegisterEvent("TITAN.EARTH_CLAP", 22000, 0)
		pUnit:RegisterEvent("TITAN.EARTH_SMASH", 15000, 0)
	end
end

function TITAN.EARTH_CombatStart(pUnit, pPlayer, event)
	if(DEBUG == true) then
	logcol(2)
	print("Debug: Earth Titan Encounter Initiated...")
	end
	local target = pUnit:GetRandomPlayer(0)
	pUnit:SendChatMessage(14, 0, "You dare challange the might of Earth?!?!")
	pUnit:RegisterEvent("TITAN.EARTH_PHASE2", 1000, 0)
	pUnit:RegisterEvent("TITAN.EARTH_SMASH", 17000, 0)
	pUnit:FullCastSpell(68594)
	if(target ~= nil) then
		pUnit:CastSpellOnTarget(61668, target)
	end
end

function TITAN.EARTH_CLAP(pUnit, pPlayer, event)
	if(DEBUG == true) then
	logcol(2)
	print("Debug: Earth Titan - Casts Thunder Clap | 71147")
	end
	pUnit:FullCastSpell(71147)
end

function TITAN.EARTH_SMASH(pUnit, pPlayer, event)
	if(DEBUG == true) then
	logcol(2)
	print("Debug: Earth Titan - Casts Smash | 26167")
	end
	pUnit:FullCastSpell(26167)
end

function TITAN.EARTH_Dies(pUnit, event)
	if(DEBUG == true) then
	logcol(2)
	print("Debug: Earth Titan Encounter Ended...[Earth Titan Dies]")
	end
	pUnit:RemoveEvents()
	pUnit:SendChatMessage(14, 0, "Earth... has failed... me...")
end

function TITAN.EARTH_LeaveCombat(pUnit, event)
	if(DEBUG == true) then
	logcol(2)
	print("Debug: Earth Titan Encounter Ended...[Earth Titan Leaves Combat]")
	end
	pUnit:RemoveEvents()
end

function TITAN.EARTH_PHASE3(pUnit, pPlayer, event)
	if(pUnit:GetHealthPct() <= 35) then
		if(DEBUG == true) then
		logcol(2)
		print("Debug: Earth Titan - Phase 3 Initiated...")
		end
		pUnit:SetCombatTargetingCapable(false)
		pUnit:SendChatMessage(14, 0, "Earth...frost...fire... The Elements used to be one. We used to be the ruling force in the world...")
		pUnit:SendChatMessage(14, 0, "But... I will show them...")
		pUnit:SendChatMessage(14, 0, "I WILL SHOW ALL OF YOU! EARTH IS THE MOST POWERFUL FORCE IN THE WORLD!")
		pUnit:RemoveEvents()
		pUnit:FullCastSpell(68594)
		pUnit:RegisterEvent("TITAN.EARTH_SMASH", 7000, 0)
		pUnit:FullCastSpell(34670)
		pUnit:RegisterEvent("TITAN.EARTH_ENABLECOM", 3000, 1)
		pUnit:RegisterEvent("TITAN.EARTH_ENRAGE", 10000, 1)
	end
end

function TITAN.EARTH_ENABLECOM(pUnit, pPlayer, event)
	pUnit:SetCombatTargetingCapable(true)
end

function TITAN.EARTH_ENRAGE(pUnit, event)
	if(DEBUG == true) then
	logcol(2)
	print("Debug: Earth Titan - Casts Enrage | 57516")
	end
	pUnit:CastSpell(57516)
end

RegisterUnitEvent(TITAN.EARTH, 1, "TITAN.EARTH_CombatStart")
RegisterUnitEvent(TITAN.EARTH, 2, "TITAN.EARTH_LeaveCombat")
RegisterUnitEvent(TITAN.EARTH, 4, "TITAN.EARTH_Dies") 